//
//  ApproveReplyTableViewCell.m
//  pushNewsManager
//
//  Created by Jobs on 8/3/17.
//  Copyright © 2017 com.Iori. All rights reserved.
//

#import "ApproveReplyTableViewCell.h"
#import "Header.h"

@implementation ApproveReplyTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

static NSString* abc[] = {@"0x008fff",@"0xff9900", @"0x428d35"};
static NSInteger insetPadding1[] = {8,8,8};
static NSInteger insetPadding2[] = {8,8,8};

-(void)didTransitionToState:(UITableViewCellStateMask)state
{
    [super didTransitionToState:state];
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        self.subviews[0].backgroundColor = [UIColor clearColor];
        NSInteger iCount = 0;
        for (UIView *view in self.subviews[0].subviews)
        {
            view.backgroundColor = [UIColor colorWithPatternImage:[self getBackgroundColorImageWithBounds:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)
                                                                                                    color:[UIColor colorWithHexString: abc[iCount] alpha:.9]
                                                                                                insetLeft:insetPadding1[iCount]
                                                                                               insetRight:insetPadding2[iCount]
                                                                   ]];
            iCount ++;
        }
        
    }
}


-(UIImage*)getBackgroundColorImageWithBounds:(CGRect)bounds color:(UIColor*)color insetLeft:(CGFloat)inset1 insetRight:(CGFloat)inset2
{
    UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    bounds = CGRectMake(bounds.origin.x + inset1,
                        bounds.origin.y,
                        bounds.size.width-inset2,
                        bounds.size.height);
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:8];
    //     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];
    
    CGContextAddPath(context, path.CGPath);
    CGContextDrawPath(context, kCGPathFill);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

#pragma mark - Image Generation -
+ (UIImage *)roundedCornerImageWithRadius:(CGFloat)radius color:(UIColor *)color
{
    UIImage *image = nil;
    
    // Make sure we have a valid color
    if (color == nil) { color = [UIColor whiteColor]; }
    
    // Rectangle if only one side is rounded, square otherwise
    CGRect rect = CGRectMake(0, 0, radius * 2, radius * 2);
    
    // Generation the image
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f);
    {
        UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:rect];
        [color set];
        [bezierPath fill];
        image = UIGraphicsGetImageFromCurrentImageContext();
    }
    UIGraphicsEndImageContext();
    
    // Make the image conform to the tint color
    return image;
}


-(void)updateContent:(id)obj
{
    
}

@end
